import 'package:animal/constant/color.dart';
import 'package:animal/constant/font.dart';
import 'package:animal/socket/socket_client.dart';
import 'package:animal/ui/login/page/pwd_login_page.dart';
import 'package:animal/ui/login/page/short_login_page.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

///登录页面
class LoginPage extends StatefulWidget {
  const LoginPage({Key? key}) : super(key: key);

  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMixin {
  //标题列表
  var tabTitle = [];

  //界面列表
  List<Widget> pageLists = [];

  //tab控制器
  late TabController tabController;

  @override
  void initState() {
    super.initState();
    tabTitle = ["短信登陆", "密码登录"];
    pageLists = [const ShortLoginPage(), const PwdLoginPage()];
    tabController = TabController(length: tabTitle.length, vsync: this);
    Get.put(ClientSocket(),permanent: true);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.white,
        body: Column(
          children: [
            Container(
              margin: EdgeInsets.only(top: ScreenUtil().L(5)),
              child: TabBar(
                tabs: tabs(),
                isScrollable: false,
                indicatorWeight: ScreenUtil().L(3),
                indicatorColor: KColorConstant.btnColorF8633B,
                unselectedLabelStyle: KFontConstant.myTextStyle(color: KColorConstant.black666666, size: 15),
                labelStyle: KFontConstant.myTextStyle(color: KColorConstant.black, size: 15, bold: true),
                labelColor: KColorConstant.black,
                labelPadding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(55)),
                indicatorSize: TabBarIndicatorSize.label,
                controller: tabController,
                indicatorPadding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(15)),
              ),
            ),
            Expanded(child: TabBarView(children: pageLists, controller: tabController)),
          ],
        ));
  }

  tabs() {
    List<Widget> items = [];
    for (int i = 0; i < tabTitle.length; i++) {
      items.add(Container(
        margin: EdgeInsets.only(top: ScreenUtil().L(30)),
        child: Tab(text: tabTitle[i]),
      ));
    }
    return items;
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(DiagnosticsProperty<TabController>('tabController', tabController));
  }
}
